package com.ly.hotel.view.fragments.vod;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;

import com.ly.hotel.adaptor.HardwareInterface;
import com.ly.hotel.view.common.PageTools;
//import com.ly.hotel.view.vod.BaseMediaControllerHolder;
//import com.ly.hotel.view.vod.BaseNativeVideoPlayerActivity;
//import com.ly.hotel.view.vod.NativeMediaController;
import com.ly.hotel.R;

/**
 * 自定义UI视频播放器页面Demo。
 * 
 * Created by Anchorer on 2014/9/23.
 */
public class NativeVideoPlayerActivity extends BaseNativeVideoPlayerActivity implements
		NativeMediaController.MediaControllerGenerator {
	BaseMediaControllerHolder holder = new BaseMediaControllerHolder();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// this.setTheme(R.style.mainStyle);

//		IntentFilter menuFilter = new IntentFilter(Constants.Broadcast.PLY_MENU);
//		this.registerReceiver(menuRev, menuFilter);
		this.className = this.getClass().getName();
		// 如果有通过Intent传入的其他数据，可以在该Activity的onCreate()方法中直接使用父类的Intent对象
		// ...
		// int videoId = mIntent.getIntExtra("videoId", 0);
		// ...

		// 如果有需要做一些监听的，可以使用父类中的MediaPlayer对象设置监听器
		// ...
		/*
		 * // 设置缓冲状态的监听器 mPlayer.setOnInfoListener(new
		 * MediaPlayer.OnInfoListener() {
		 * 
		 * @Override public boolean onInfo(MediaPlayer mp, int what, int extra)
		 * { return false; } });
		 */
		// ...
		HardwareInterface.setFullScreen();
	}

	@Override
	public BaseMediaControllerHolder generateMediaController() {
		LayoutInflater inflater = LayoutInflater.from(this);
		View view = inflater.inflate(R.layout.video_native_media_controler_custom, null);

		holder.parentLayout = view;
//		holder.bottomMenuview = (BottomMenuView) view.findViewById(R.id.bottomview);
		holder.returnButton = (ImageButton) view.findViewById(R.id.video_native_media_controller_custom_btn_return);
		holder.pauseButton = (ImageButton) view.findViewById(R.id.video_native_media_controller_custom_btn_start);
//		holder.menuButton = (ImageButton) view.findViewById(R.id.video_native_media_controller_custom_btn_menu);
		holder.currentTimeView = (TextView) view.findViewById(R.id.video_native_media_controller_custom_currenttime);
		holder.totalTimeView = (TextView) view.findViewById(R.id.video_native_media_controller_custom_totaltime);
		holder.filmName = (TextView) view.findViewById(R.id.video_native_media_controller_custom_film_name);
		holder.timeView = (TextView) view.findViewById(R.id.video_native_media_controller_custom_time);
		holder.seekbar = (SeekBar) view.findViewById(R.id.video_native_media_controller_custom_seekbar);
		holder.volumeSeekbar = (SeekBar) view.findViewById(R.id.video_native_media_controller_custom_volume_sebar);
		holder.muteButton = (ImageButton) view.findViewById(R.id.video_native_media_controller_custom_volume_mute);
		holder.pauseResId = R.xml.selector_video_btn_pause;
		holder.startResId = R.xml.selector_video_btn_start;
		holder.returnResId = R.xml.selector_video_btn_return;
		holder.app = app;
		
		Log.i("medio", filmName);
		holder.filmName.setText(filmName);
		return holder;
	}

//	BroadcastReceiver menuRev = new BroadcastReceiver() {
//		@Override
//		public void onReceive(Context cont, Intent inte) {
//			if (app.isBottomShow() && holder.bottomMenuview != null) { // 打开
//				holder.bottomMenuview.setVisibility(View.VISIBLE);
//				holder.bottomMenuview.register();
//			} else { // 关闭
//				holder.bottomMenuview.setVisibility(View.GONE);
//				holder.bottomMenuview.destroy();
//			}
//		}
//	};

	@Override
	protected void onPause() {
		/*留位和挂机页面，不需要结束*/
		if(!PageTools.isPopWindow(app)){
			Log.i(className, "非留位界面，退出之");
//			HardwareInterface.setMuteFlag(true);
			finish();
		}
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
//		this.unregisterReceiver(menuRev);
	}

}
